/*
 * COPYRIGHT. ShenZhen JiMi Technology Co., Ltd. 2017.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen JiMi Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * 2017年7月4日    Li.Shangzhi         Create the class
 * http://www.jimilab.com/
 */

package com.jimi.framework.swagger;

import io.swagger.models.Path;
import io.swagger.models.Swagger;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.stereotype.Component;

/**
 * @FileName CoustomSwagger.java
 * @Description:
 *
 * @Date 2017年7月4日 上午10:25:19
 * @author Li.Shangzhi
 * @version 1.0
 */
@Component
public class CoustomSwagger extends Swagger {

	@Override
	public Map<String, Path> getPaths() {
		if (paths == null) {
			return null;
		}
		Map<String, String> tempMap = new HashMap<>();

		Set<Entry<String, Path>> set = paths.entrySet();
		Iterator<Entry<String, Path>> iter = set.iterator();
		while (iter.hasNext()) {
			Entry<String, Path> entry = iter.next();
			Path path = entry.getValue();
			tempMap.put(path.getOptions().getOperationId(), entry.getKey());
		}

		int count = tempMap.size();
		Map<String, Path> sorted = new LinkedHashMap<>();
		for (int i = 0; i < count; i++) {
			String key = tempMap.get(String.valueOf(i));
			sorted.put(key, paths.get(key));
		}
		return sorted;
	}
}
